package org.yfdl.controller;



import org.yfdl.entity.UserRole;
import org.yfdl.service.UserRoleService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * (UserRole)表控制层
 *
 * @author makejava
 * @since 2024-01-23 12:47:05
 */
@RestController
@RequestMapping("userRole")
public class UserRoleController {
    /**
     * 服务对象
     */
    @Resource
    private UserRoleService userRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<UserRole> selectOne(@PathVariable Serializable id) {
        return ResponseEntity.ok(this.userRoleService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param userRole 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public ResponseEntity<Boolean> insert(@RequestBody UserRole userRole) {
        return ResponseEntity.ok(this.userRoleService.save(userRole));
    }

    /**
     * 修改数据
     *
     * @param userRole 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody UserRole userRole) {
        return ResponseEntity.ok(this.userRoleService.updateById(userRole));
    }

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> delete(@PathVariable("id") Serializable id) {
        return ResponseEntity.ok(this.userRoleService.removeById(id));
    }
}
